﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;

namespace NHDemo
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }
        private System.Timers.Timer timer;  
        protected override void OnStart(string[] args)
        {
            timer = new System.Timers.Timer(5000);
            timer.Elapsed+=new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Start();
        }
        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer.Stop();
            MessageBox.Show(DateTime.Now.ToLongTimeString());
            timer.Start(); 
        }

        protected override void OnStop()
        {
            timer.Stop(); 
            timer.Dispose();  

        }
    }
}
